package com.yjz.middleware.netty.one_BIO;

import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.charset.Charset;

/**
 * @Desc Bio 客户端
 * @Author: jinzhong.yuan
 * @Date: 2018/12/25 11:14
 */
@Slf4j
public class BioClient {

  public static void main(String[] args) throws IOException {
    Socket socket = new Socket();
    socket.connect(new InetSocketAddress("127.0.0.1", 2189));
    OutputStream os = socket.getOutputStream();
    os.write("你好,我是客户端".getBytes(Charset.defaultCharset()));
    socket.shutdownOutput();
    InputStream is = socket.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    String line = reader.readLine();
    log.info("读取服务端的消息: {}", line);
    socket.shutdownInput();
  }
}
